// Functions associated with the Cursor class
//-----------------

//-----------------
// Includes libraries and other files
#include "Cursor.h"
//-----------------

//-----------------
//// CONSTRUCTOR - Cursor
Cursor::Cursor()
	: device_( nullptr), active_( false)
{}

//// DESTRUCTOR - ~Cursor
Cursor::~Cursor() {
	device_ = nullptr;
}
//-----------------

//-----------------
//// FUNCTION - visible
// return whether the cursor is currently visible or not
bool Cursor::visible() const {
	// Pre-conditions :- none
	assert( true);

	return visible_;
}

//// FUNCTION - active
// return whether the cursor is currently active or not
bool Cursor::active() const {
	// Pre-conditions :- none
	assert( true);

	return active_;
}

//// FUNCTION - get_x
// return the x position of the cursor
int Cursor::get_x() const {
	// Pre-conditions :- none
	assert( true);

	return x_;
}

//// FUNCTION - get_y
// return the y position of the cursor
int Cursor::get_y() const {
	// Pre-conditions :- none
	assert( true);

	return y_;
}

//// FUNCTION - render
// output the cursor to the device
void Cursor::render( const float& z, const float& sz, const float& w, const float& h) const {
	// Pre-conditions :- the device must exist
	assert( device_ != nullptr);

	if( visible_) {
		// manipulate the x and y co-ordinates so they fit on the orthographic projection window (i.e. 1x1)
		float x( (x_/w)-0.5f), y( (y_/h)-0.5f);

		if( active_)
			cursor_active_.render( x, y, z, CURSOR_SCALE/w, CURSOR_SCALE/h, sz);
		else
			cursor_inactive_.render( x, y, z, CURSOR_SCALE/w, CURSOR_SCALE/h, sz);
	}
}

//// FUNCTION - setup_geometry
// create the objects that will be used
HRESULT Cursor::setup_geometry( LPDIRECT3DDEVICE9& device) {
	// Pre-conditions :- the device must exist
	assert( device != nullptr);

	HRESULT hr;
	device_ = device;

	hr =	  cursor_active_.load_mesh(		device_, "object_cursor_active.x");
	hr = hr | cursor_inactive_.load_mesh(	device_, "object_cursor_inactive.x");

	return hr;
}

//// FUNCTION - set_position
// set the x and y position of the cursor
void Cursor::set_position( const float& x, const float& y) {
	// Pre-conditions :- none
	assert( true);

	x_ = x;
	y_ = y;
}

//// FUNCTION - set_visible
// set the mouse cursor's visibility (i.e. whether it should be used or not)
void Cursor::set_visible( bool v) {
	// Pre-conditions :- none
	assert( true);

	visible_ = v;
}

//// FUNCTION - set_active
// set the mouse cursor's activity so it changes to icon accordingly
void Cursor::set_active( bool a) {
	// Pre-conditions :- none
	assert( true);

	active_ = a;
}